package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaItem;
import com.ruoyi.system.domain.JiajiaHospital;
import com.ruoyi.system.service.IJiajiaHospitalService;
import com.ruoyi.system.service.IJiajiaItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医院社区Controller
 * 
 * @author mrwang
 * @date 2024-05-06
 */
@Controller
@RequestMapping("/jiajia/hospital")
public class JiajiaHospitalController extends BaseController
{
    private String prefix = "jiajia/hospital";

    @Autowired
    private IJiajiaHospitalService jiajiaHospitalService;
    @Autowired
    private IJiajiaItemService jiajiaItemService;

    @RequiresPermissions("system:hospital:view")
    @GetMapping()
    public String hospital()
    {
        return prefix + "/hospital";
    }

    /**
     * 查询医院社区列表
     */
    @RequiresPermissions("system:hospital:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaHospital jiajiaHospital)
    {
        startPage();
        List<JiajiaHospital> list = jiajiaHospitalService.selectJiajiaHospitalList(jiajiaHospital);
        return getDataTable(list);
    }

    /**
     * 导出医院社区列表
     */
    @RequiresPermissions("system:hospital:export")
    @Log(title = "医院社区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaHospital jiajiaHospital)
    {
        List<JiajiaHospital> list = jiajiaHospitalService.selectJiajiaHospitalList(jiajiaHospital);
        ExcelUtil<JiajiaHospital> util = new ExcelUtil<JiajiaHospital>(JiajiaHospital.class);
        return util.exportExcel(list, "医院社区数据");
    }

    /**
     * 新增医院社区
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        List<JiajiaItem> itemList = jiajiaItemService.selectJiajiaItemList(new JiajiaItem());
        mmap.put("itemList", itemList);
        return prefix + "/add";
    }

    /**
     * 新增保存医院社区
     */
    @RequiresPermissions("system:hospital:add")
    @Log(title = "医院社区", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaHospital jiajiaHospital)
    {
        return toAjax(jiajiaHospitalService.insertJiajiaHospital(jiajiaHospital));
    }

    /**
     * 修改医院社区
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaHospital jiajiaHospital = jiajiaHospitalService.selectJiajiaHospitalById(id);
        mmap.put("jiajiaHospital", jiajiaHospital);
        List<JiajiaItem> itemList = jiajiaItemService.selectJiajiaItemList(new JiajiaItem());
        return prefix + "/edit";
    }

    /**
     * 修改保存医院社区
     */
    @RequiresPermissions("system:hospital:edit")
    @Log(title = "医院社区", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaHospital jiajiaHospital)
    {
        return toAjax(jiajiaHospitalService.updateJiajiaHospital(jiajiaHospital));
    }

    /**
     * 删除医院社区
     */
    @RequiresPermissions("system:hospital:remove")
    @Log(title = "医院社区", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaHospitalService.deleteJiajiaHospitalByIds(ids));
    }
}
